package com.tjl.warehouse.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tjl.warehouse.exception.ThrowUtils;
import com.tjl.warehouse.model.MyPage;
import com.tjl.warehouse.model.Store;
import com.tjl.warehouse.model.dto.StoreReq;
import com.tjl.warehouse.service.StoreService;
import com.tjl.warehouse.mapper.StoreMapper;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
* @author Tang
* @description 针对表【store(仓库表)】的数据库操作Service实现
* @createDate 2024-05-31 21:11:49
*/
@Service
public class StoreServiceImpl extends ServiceImpl<StoreMapper, Store>
    implements StoreService{

    @Resource
    private StoreMapper storeMapper;

    @Override
    public MyPage<Store> getPage(StoreReq req, MyPage<Store> myPage) {
        //校验参数
        ThrowUtils.throwIfParams(myPage == null);
        ThrowUtils.throwIfParams(myPage.getPageNum() <= 0, "页码最小为1");
        ThrowUtils.throwIfParams(myPage.getPageSize() > 500, "最大每页500条");
        var query = new LambdaQueryWrapper<Store>();
        query.like(StringUtils.isNotBlank(req.getStoreName()), Store::getStoreName, req.getStoreName())
                .like(StringUtils.isNotBlank(req.getStoreAddress()), Store::getStoreAddress, req.getStoreAddress())
                .like(StringUtils.isNotBlank(req.getPhone()), Store::getPhone, req.getPhone());

        IPage<Store> resultPage = storeMapper.selectPage(myPage.toPage(), query);
        return new MyPage<>(resultPage);
    }
}




